package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqEnum;
import cloud.maque.admin.domain.vo.EnumVo;
import cloud.maque.admin.service.MqEnumService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 字典接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/enum")
@Api(tags = "运维-字典接口")
public class EnumController {

    @Autowired
    MqEnumService enumService;


    @PostMapping("/page")
    @ApiOperation(value = "字典查询")
    @TenantQuery
    public ResponseBodyVo<PageInfo<MqEnum>> page(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqEnum> pageReq) {
        return ResponseBodyVo.Success(enumService.page(pageReq));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情")
    public ResponseBodyVo<EnumVo> Detail(@PathVariable("id") String enumId, @RequestParam(name = "fieldId", required = false) String fieldId) {
        return ResponseBodyVo.Success(enumService.Detail(enumId, fieldId));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除字典")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@PathVariable("id") String enumId, @TenantId String tenantId) {
        return ResponseBodyVo.Success(enumService.deleteByIdAndTenantId(enumId, tenantId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增字典")
    public ResponseBodyVo<MqEnum> Save(@RequestBody @ApiParam("内容") MqEnum mqEnum) {
        return ResponseBodyVo.Success(enumService.saveEnum(mqEnum));
    }

}
